<template>
  <div class="logout-dialog">
    <div class="dialog-header">
      <h3>确认退出</h3>
      <button @click="$emit('close')" class="close-btn">×</button>
    </div>
    <div class="dialog-content">
      <p>确定要退出当前账户吗？</p>
      <p>退出后您需要重新登录才能访问个人功能。</p>
    </div>
    <div class="dialog-actions">
      <button @click="$emit('close')" class="cancel-btn">取消</button>
      <button @click="confirmLogout" class="confirm-btn">确认退出</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LogoutConfirmModal',
  methods: {
    confirmLogout() {
      // 清除前台用户登录信息
      localStorage.removeItem('userToken');
      localStorage.removeItem('userTokenExpiry');
      localStorage.removeItem('userId');
      localStorage.removeItem('username');
      localStorage.removeItem('userEmail');
      localStorage.removeItem('userInfo');
      
      // 清理旧的key以防冲突
      localStorage.removeItem('token');
      localStorage.removeItem('userRole');
      localStorage.removeItem('tokenExpiry');

      this.$root.showToast('已退出登录', 'success');
      this.$emit('close');

      // 刷新登录状态
      if (this.$root.refreshLoginStatus) {
        this.$root.refreshLoginStatus();
      }

      // 跳转到首页
      this.$router.push('/');
    }
  }
}
</script>

<style scoped>
.logout-dialog {
  background: #181818;
  border-radius: 8px;
  width: 500px;
  overflow: hidden;
  animation: slideIn 0.3s ease;
  border: 1px solid #333;
}

.dialog-header {
  padding: 20px 24px;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-header h3 {
  margin: 0;
  color: white;
  font-size: 18px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: #b3b3b3;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.dialog-content {
  padding: 24px;
  color: #b3b3b3;
  line-height: 1.5;
}

.dialog-content p {
  margin: 0 0 16px 0;
}

.dialog-content p:last-child {
  margin-bottom: 0;
}

.dialog-actions {
  padding: 16px 24px 24px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.cancel-btn,
.confirm-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 80px;
}

.cancel-btn {
  background: transparent;
  color: #b3b3b3;
  border: 1px solid #535353;
}

.cancel-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-color: #727272;
}

.confirm-btn {
  background: #1db954;
  color: black;
}

.confirm-btn:hover:not(:disabled) {
  background: #1ed760;
  transform: scale(1.02);
}

.confirm-btn:disabled {
  background: #535353;
  cursor: not-allowed;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style> 